package com.blog.service.Impl;

import java.util.List;

import com.blog.BO.AdminBO;
import com.blog.BO.PlateBO;
import com.blog.dao.AdminDao;
import com.blog.dao.AllPlateDao;
import com.blog.dao.AllPostDao;
import com.blog.dao.CheckPostDao;
import com.blog.dao.CheckUserDao;
import com.blog.dao.UserDao;
import com.blog.dao.impl.AdminDaoImpl;
import com.blog.dao.impl.AllPlateDaoImpl;
import com.blog.dao.impl.AllPostDaoImpl;
import com.blog.dao.impl.CheckPostDaoImpl;
import com.blog.dao.impl.CheckUserDaoImpl;
import com.blog.dao.impl.UserDaoImpl;
import com.blog.entity.Admin;
import com.blog.entity.Page;
import com.blog.entity.Plate;
import com.blog.entity.Post;
import com.blog.entity.User;
import com.blog.service.AdminService;

public class AdminServiceImpl implements AdminService {
	private AdminDao ad= new AdminDaoImpl();
	private AllPlateDao apd=new AllPlateDaoImpl();
	private UserDao ud=new UserDaoImpl();
	private CheckUserDao cud=new CheckUserDaoImpl();
	private AllPostDao ap=new AllPostDaoImpl();
	private CheckPostDao cpd = new CheckPostDaoImpl();
	@Override
	public Admin selectAdminByName(Admin admin) {
		// TODO Auto-generated method stub
		return ad.selectAdminByAdminNameAndAdminPass(admin.getAdminName(), admin.getAdminPass());
	}

	@Override
	public Page<User> selectAllUser(int pageNum, int pageSize) {
		// TODO Auto-generated method stub
		List<User> data=ud.selectUser(null, pageNum, pageSize);
		int total =ud.selectUserNum();
		return new Page<User>(data, pageNum, pageSize, total);
	}

	@Override
	public Page<Admin> selectAllAdmin(int pageNum, int pageSize) {
		// TODO Auto-generated method stub
		List<Admin> list=ad.selectAdmin(null, pageNum, pageSize);
		int total=ad.selectAdminNum();
		return new Page<Admin>(list, pageNum, pageSize, total);
	}

	@Override
	public int deleteAdminById(Admin admin) {
		// TODO Auto-generated method stub
		int num = ad.deleteAdminByAdminId(admin.getAdminId());
		return num;
	}

	@Override
	public int updataAdminById(Admin admin) {
		// TODO Auto-generated method stub
		return ad.updateAdmin(admin);
	}

	@Override
	public int insertAdmin(Admin admin) {
		// TODO Auto-generated method stub
		Admin adm=ad.selectAdminByAdminName(admin.getAdminName());
		if(adm!= null){
			return -1;
		}
		return ad.insertAdmin(admin);
	}

	@Override
	public int deleteUserById(User user) {
		// TODO Auto-generated method stub
		return ud.deleteUserByUserId(user.getUserId());
	}

	@Override
	public int upateAdminById(User user) {
		// TODO Auto-generated method stub
		return ud.updateUser(user);
	}

	@Override
	public Page<User> selectAllUserByCheck(int pageNum, int pageSize) {
		// TODO Auto-generated method stub
		List<User> data=cud.selectCheckUser(null, pageNum, pageSize);
		int total =cud.selectCheckUserNum();
		return new Page<User>(data, pageNum, pageSize, total);
	}

	@Override
	public Page<Plate> selectAllPlate(int pageNum, int pageSize) {
		// TODO Auto-generated method stub
		List<Plate> data= apd.selectPlate(null, pageNum, pageSize);
		int totalRows=apd.selectPlateNum();
		return new Page<Plate>(data, pageNum, pageSize, totalRows);
	}

	@Override
	public int insertPlate(Plate plate) {
		// TODO Auto-generated method stub
		Plate data=apd.selectPlateByPlateName(plate.getPlateName());
		if(data!=null) {
			return -1;
		}
		return apd.insertPlate(plate);
	}

	@Override
	public int deletePlateById(Plate plate) {
		// TODO Auto-generated method stub
		return apd.deletePlateByPlateId(plate.getPlateId());
	}

	@Override
	public int updataPlateById(Plate plate) {
		// TODO Auto-generated method stub
		return apd.updatePlate(plate);
	}

	@Override
	public Page<Post> selectPost(int pageNum, int pageSize) {
		// TODO Auto-generated method stub
		List<Post> data=ap.selectPost(null, pageNum, pageSize);
		int total =ap.selectPostNum();
		return new Page<Post>(data, pageNum, pageSize, total);
	}

	@Override
	public int deletePostById(Post post) {
		// TODO Auto-generated method stub
		return ap.deletePostByPostId(post.getPostId());
	}

	@Override
	public int updataPostByPostId(Post post) {
		// TODO Auto-generated method stub
		return ap.updatePost(post);
	}

	@Override
	public Page<Post> selectAllPostByCheck(int pageNum, int pageSize) {
		// TODO Auto-generated method stub
		List<Post> data=cpd.selectCheckPost(null, pageNum, pageSize);
		int total =cpd.selectCheckPostNum();
		return new Page<Post>(data, pageNum, pageSize, total);
	}

	@Override
	public Admin selectAdminByid(Admin admin) {
		// TODO Auto-generated method stub
		AdminBO ab =new AdminBO();
		ab.setAdminId(admin.getAdminId());
		List<Admin> admin1=ad.selectAdmin(ab, 1, 1);
		return admin1.get(0);
	}

}
